<?php
/**
 * rakuten日志
 * (rakuten-model)
 */

namespace App\Models\Rakuten;

use Illuminate\Database\Eloquent\Model;

class RakutenLogs extends Model{

    protected $connection = 'mysql_rakuten';

    protected $table = 'rakuten_logs';

    protected $guarded  = [];

    public static $orderSync = 'order_sync';
    public static $customerOrderSync = 'customer_order_sync';
    public static $customerOrderException = 'customer_order_exception';
    public static $customerOrderLogistics = 'customer_order_logistics';

    public static $overseasInboundOrder = 'overseas_inbound_order'; //海外仓(谷仓)入库订单
    public static $overseasInboundOrderDetail = 'overseas_inbound_order_detail'; //海外仓(谷仓)入库订单明细

    public static $overseasOrder = 'overseas_order'; //海外仓(谷仓)出库订单
    public static $overseasOrderError = 'overseas_order_error'; //海外仓(谷仓)出库订单异常
    public static $overseasOrderProductSku = 'overseas_order_product_sku'; //海外仓(谷仓)出库订单产品
    public static $overseasOrderShippingMethod = 'overseas_order_shipping_method'; //海外仓(谷仓)出库订单发货方式
    public static $overseasCustomerOrderSync = 'overseas_customer_order_sync';
    public static $overseasProductInventory = 'overseas_product_inventory'; //海外仓(谷仓)产品库存

    /**
     * 添加日志
     * @param $type
     * @param $content
     * @param array $logData
     * @param null $orderIds
     * @return \Illuminate\Database\Eloquent\Builder|Model
     */
    public static function logs($type, $content, $logData = [], $orderIds = []){
        return self::query()->create([
            'type' => $type,
            'content' => $content,
            'data' => json_encode($logData),
            'order_ids' => json_encode($orderIds)
        ]);
    }

}
